home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / C / LIB / UNIXLIB37B / !UnixLib37 / src / resource / c / getprior next >
Text File  |  1996-11-09  |  2KB  |  71 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /unixb/home/unixlib/source/unixlib37/src/resource/c/RCS/getprior,v $
  4.  * $Date: 1996/05/06 09:01:33 $
  5.  * $Revision: 1.2 $
  6.  * $State: Rel $
  7.  * $Author: unixlib $
  8.  *
  9.  * $Log: getprior,v $
  10.  * Revision 1.2  1996/05/06 09:01:33  unixlib
  11.  * Updates to sources made by Nick Burrett, Peter Burwood and Simon Callan.
  12.  * Saved for 3.7a release.
  13.  *
  14.  * Revision 1.1  1996/04/19 21:29:28  simon
  15.  * Initial revision
  16.  *
  17.  ***************************************************************************/
  18.  
  19. static const char rcs_id[] = "$Id: getprior,v 1.2 1996/05/06 09:01:33 unixlib Rel $";
  20.  
  21. #include <errno.h>
  22. #include <sys/resource.h>
  23. #include <sys/unix.h>
  24. #include <limits.h>
  25.  
  26. /* Return the highest priority of any process specified by 'which' and 'who'
  27.    (see <sys/resource.h>); if WHO is zero, the current process, process group,
  28.    or user (as specified by WHO) is used.  A lower priority number means higher
  29.    priority.  Priorities range from PRIO_MIN to PRIO_MAX.  */
  30. int
  31. getpriority (enum __priority_which which, int who)
  32. {
  33.   int i;
  34.  
  35.   if (who == 0)
  36.     {
  37.       /* Return priorities of the current process.  */
  38.       switch (which)
  39.     {
  40.     case PRIO_PROCESS:
  41.       return __u->ppri;
  42.     case PRIO_PGRP:
  43.       return __u->gpri;
  44.     case PRIO_USER:
  45.       return __u->upri;
  46.     default:
  47.       errno = EINVAL;
  48.       return -1;
  49.     }
  50.       return -1;
  51.     }
  52.   for (i = 0; i < CHILD_MAX; i++)
  53.     {
  54.       switch (which)
  55.     {
  56.     case PRIO_PROCESS:
  57.       return __u->child[i].ppri;
  58.     case PRIO_PGRP:
  59.       return __u->child[i].gpri;
  60.     case PRIO_USER:
  61.       return __u->child[i].upri;
  62.     default:
  63.       errno = EINVAL;
  64.       return -1;
  65.     }
  66.     }
  67.   /* Invalid value of 'which'.  */
  68.   errno = ESRCH;
  69.   return -1;
  70. }
  71.